#pragma once
#include<unordered_map>
#include<functional>
#include<iostream>
#include<unistd.h>

using task_t=std::function<void()>;
static size_t num=0;

void download()
{
    std::cout<<"正在下载……"<<std::endl;
}

void log()
{
    std::cout<<"正在写入日志……"<<std::endl;
}

void update()
{
    std::cout<<"正在更新……"<<std::endl;
}

class TaskManager
{
public:
    TaskManager()
    {
        insert(log);
        insert(download);
        insert(update);
    }

    void insert(task_t task)
    {
        tm_map[num++]=task;
    }

    void ExecuteTask(int code)
    {
        if(tm_map.find(code)==tm_map.end())
        {
            std::cout<<"excute task no find"<<std::endl;
            return;
        }
        tm_map[code]();
        sleep(1);
    }
private:
    std::unordered_map<int,task_t> tm_map;
};